<?php

/**
 * @author @author Samrat Khan & Sadik Sarfaraz - Apr 13, 2013
 */

    require('top.inc.php');
    $formLoad = new Form();
?>
<?php
if(isset($_SESSION['user']) && $_SESSION['user']['utype'] == 1) {
    if(isset($_POST['addCustomer'])) {
        $query = "INSERT INTO customerinfo ( cusname, cusaddress, keycontact_person, cellnumber, inserteddate ) VALUES ( :cusname, :cusaddress, :keycontact_person, :cellnumber, :inserteddate )";
        $query_params = array(
            ':cusname' => $_POST['cusname'],
            ':cusaddress' => $_POST['cusaddress'],
            ':keycontact_person' => $_POST['keycontact_person'],
            ':cellnumber' => $_POST['cellnumber'],
            ':inserteddate' => date('Y-m-d H:i:s')
        );
        
        try {
            $stmt = $db->prepare($query);
            $result = $stmt->execute($query_params);
        } catch (PDOException $ex) {
            die("Failed to run query: " . $ex->getMessage());
        }
        if($result) {
            echo $msg['38'];
        }
    } else {
?>
<form class="form-horizontal" action="" method="post" id="addCustomer">
    <div class="control-group">
        <label class="control-label" for="cusname"><?php echo $customer_info['cusname']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField('cusname', "span2", "", $customer_info['cusname']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="cusaddress"><?php echo $customer_info['cusaddress']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textArea('cusaddress', 'span5', ''); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="keycontact_person"><?php echo $customer_info['keycontact_person']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField('keycontact_person', "span2", "", $customer_info['keycontact_person']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="cellnumber"><?php echo $customer_info['cellnumber']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField('cellnumber', "span2", "", $customer_info['cellnumber']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="inputCustomer">&nbsp;</label>
        <div class="controls"><input class="btn btn-primary" type="submit" value="Add Customer" name="addCustomer" /></div>
    </div>
</form>
<?php
    }
} else {
    header("Location: login.php");
}
    include ('bottom.inc.php');
?>

